package com.sz.myinterface;

import com.aliyun.api.gateway.demo.util.HttpUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class Address {

    public static String getaddress() {

        String host = "https://api01.aliyun.venuscn.com";
        String path = "/ip";
        String method = "GET";
        String appcode = "045ca0303c534d55bec9100912040eb5";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("ip", "localhost");

        String bodystr = "";
        try {
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            //System.out.println(response.toString());
            //获取response的body
            bodystr = EntityUtils.toString(response.getEntity());

            //System.out.println(bodystr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bodystr;
    }

    public static void main(String[] args) {

        System.out.println(getaddress());
    }

}